﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace lcmyjobs.DAL
{
	/// <summary>
	/// 数据访问类:enterprise_collection
	/// </summary>
	public partial class enterprise_collection
	{
		public enterprise_collection()
		{}
        /// <summary>
        /// 分页获取应聘职位简历信息列表
        /// </summary>
        /// <param name="enterprise_bid">企业ID</param>
        /// <param name="currentPageIndex">当前页</param>
        /// <param name="pageSize">每页显示条目数</param>
        /// <param name="count">总条目数</param>
        /// <returns>返回的DataSet第2个表是企业名称</returns>
        public DataSet GetCollection(int enterprise_bid, int currentPageIndex, int pageSize, out int count)
        {
            SqlParameter[] para = 
            {
                new SqlParameter("@enterprise_bid",SqlDbType.Int),
                new SqlParameter("@currentPageIndex",SqlDbType.Int),
                new SqlParameter("@pageSize",SqlDbType.Int),
                new SqlParameter("@count",SqlDbType.Int)
            };

            para[0].Value = enterprise_bid;
            para[1].Value = currentPageIndex;
            para[2].Value = pageSize;
            para[3].Direction = ParameterDirection.Output;

            DataSet ds = DbHelperSQL.RunProcedure("P_Get_enterprise_colleciton", para, "ds");

            count = Convert.ToInt32(para[3].Value);


            return ds;
        }

		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("enterprise_cid", "enterprise_collection"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int enterprise_cid)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_cid", SqlDbType.Int,4)
};
			parameters[0].Value = enterprise_cid;

			int result= DbHelperSQL.RunProcedure("enterprise_collection_Exists",parameters,out rowsAffected);
			if(result==1)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		///  增加一条数据
		/// </summary>
		public int Add(lcmyjobs.Model.enterprise_collection model)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_cid", SqlDbType.Int,4),
					new SqlParameter("@uid", SqlDbType.Int,4),
					new SqlParameter("@collectiontime", SqlDbType.DateTime),
					new SqlParameter("@exterprise_bid", SqlDbType.Int,4)};
			parameters[0].Direction = ParameterDirection.Output;
			parameters[1].Value = model.uid;
			parameters[2].Value = model.collectiontime;
			parameters[3].Value = model.exterprise_bid;

			DbHelperSQL.RunProcedure("enterprise_collection_ADD",parameters,out rowsAffected);
			return (int)parameters[0].Value;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public bool Update(lcmyjobs.Model.enterprise_collection model)
		{
			int rowsAffected=0;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_cid", SqlDbType.Int,4),
					new SqlParameter("@uid", SqlDbType.Int,4),
					new SqlParameter("@collectiontime", SqlDbType.DateTime),
					new SqlParameter("@exterprise_bid", SqlDbType.Int,4)};
			parameters[0].Value = model.enterprise_cid;
			parameters[1].Value = model.uid;
			parameters[2].Value = model.collectiontime;
			parameters[3].Value = model.exterprise_bid;

			DbHelperSQL.RunProcedure("enterprise_collection_Update",parameters,out rowsAffected);
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int enterprise_cid)
		{
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from enterprise_collection ");
            strSql.Append(" where enterprise_cid=@enterprise_cid");

            SqlParameter[] parameters = {
					new SqlParameter("@enterprise_cid", SqlDbType.Int,4)
};
            parameters[0].Value = enterprise_cid;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string enterprise_cidlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from enterprise_collection ");
			strSql.Append(" where enterprise_cid in ("+enterprise_cidlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public lcmyjobs.Model.enterprise_collection GetModel(int enterprise_cid)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_cid", SqlDbType.Int,4)
};
			parameters[0].Value = enterprise_cid;

			lcmyjobs.Model.enterprise_collection model=new lcmyjobs.Model.enterprise_collection();
			DataSet ds= DbHelperSQL.RunProcedure("enterprise_collection_GetModel",parameters,"ds");
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["enterprise_cid"]!=null && ds.Tables[0].Rows[0]["enterprise_cid"].ToString()!="")
				{
					model.enterprise_cid=int.Parse(ds.Tables[0].Rows[0]["enterprise_cid"].ToString());
				}
				if(ds.Tables[0].Rows[0]["uid"]!=null && ds.Tables[0].Rows[0]["uid"].ToString()!="")
				{
					model.uid=int.Parse(ds.Tables[0].Rows[0]["uid"].ToString());
				}
				if(ds.Tables[0].Rows[0]["collectiontime"]!=null && ds.Tables[0].Rows[0]["collectiontime"].ToString()!="")
				{
					model.collectiontime=DateTime.Parse(ds.Tables[0].Rows[0]["collectiontime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["exterprise_bid"]!=null && ds.Tables[0].Rows[0]["exterprise_bid"].ToString()!="")
				{
					model.exterprise_bid=int.Parse(ds.Tables[0].Rows[0]["exterprise_bid"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select enterprise_cid,uid,collectiontime,exterprise_bid ");
			strSql.Append(" FROM enterprise_collection ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" enterprise_cid,uid,collectiontime,exterprise_bid ");
			strSql.Append(" FROM enterprise_collection ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "enterprise_collection";
			parameters[1].Value = "enterprise_cid";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

